
import { Promise } from 'es6-promise'
import  { mapGetters, mapActions }  from 'vuex'

const mixin = {

    data() {
        return {
            modalReportConfirmText:'',
            modalReportCloseText:'',
            modalReportTips:'',
            show_modal_report:false,
        }
    },
    computed:{
        ...mapGetters([
            'localInfo'
        ]),
        userInfo(){
            return this.localInfo.userInfo
        },
    },
    methods: {
        // actions
        ...mapActions([
            'setUserInfo',
        ]),
        goReport(){
            this.show_modal_report = false
            this.$router.push({
                name:'user-credit-report-index'
            })
        },
        cancle(){
            location.href = 'tel://87098933';
        },
        setAuth(){
            if(this.$route.query.status) return

            if(this.$route.name == 'share-loan-in' || this.$route.name == 'share-loan-out' ) return

            if(this.userInfo.isExpired){
                this.show_modal_report = true
                this.modalReportTips = '信用报告已经过期失效，需重新认证后才能借款/出借。'
                this.modalReportConfirmText = '去重新认证'
                return
            }
            if(this.userInfo.bankcard){
                if(this.userInfo.noZmxy || this.userInfo.noOperators ){
                    this.show_modal_report = true
                    this.modalReportTips = '您尚未完成信用报告认证，7日内前往“账户-我的”进行补充完善。'
                    this.modalReportConfirmText = '去完成认证'
                }
            }
        }
    },
    created(){
        this.userInfoGetting && this.userInfoGetting()
        if(!this.userInfo){
            this.setUserInfo()
            .then(result=>{
                this.setAuth()
                this.userInfoCallback && this.userInfoCallback(this.userInfo)
            })
            .catch(error => {
                if(error == 'goWeChat'){
                    return
                }
                this.setAuth()
                this.userInfoCallback && this.userInfoCallback(this.userInfo)
                console.error(error)
            })
        }
        else{
            this.setAuth()
            this.userInfoCallback && this.userInfoCallback(this.userInfo)
        }
    }
}

export default mixin